/*
 * EditingInstance.java
 * 
 * Created by demory on Nov 21, 2009, 8:58:52 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart;

import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.fpdev.apps.cart.gui.EditorFrame;
import org.fpdev.apps.cart.network.CartNetwork;
import org.fpdev.apps.cart.network.Line;
import org.fpdev.apps.cart.network.LineStyles;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author demory
 */
public class Editor {

  private int id_;

  private CartDocument doc_;

  private EditorFrame frame_;

  // the action history (for undo/redo support)
  private CartActionHistory history_;

  private Line selectedLine_;

  private Map<Property, String> props_;



  public enum Property {
    SHOW_ANCHORS,
    SHOW_CORRIDORS,
    SHOW_LINES,
    SHOW_GRID,
    SNAP_TO_GRID,
    USE_ANTIALIASING
  }

  public Editor(int id, CartDocument doc, CartActionHistory history) {
    id_ = id;
    doc_ = doc;
    history_ = history;
    history.setEditor(this);
    
    props_ = new HashMap<Property, String>();
    initProperties();
  }

  public int getID() {
    return id_;
  }

  public CartDocument getDocument() {
    return doc_;
  }

  public CartActionHistory getHistory() {
    return history_;
  }

  public EditorFrame getFrame() {
    return frame_;
  }

  public void setFrame(EditorFrame frame) {
    frame_ = frame;
  }

  public Line getSelectedLine() {
    return selectedLine_;
  }

  public void setSelectedLine(Line selectedLine) {
    selectedLine_ = selectedLine;
  }

  public String getProperty(Property prop) {
    return props_.get(prop);
  }

  public boolean getBoolProperty(Property prop) {
    return getProperty(prop).equals("true");
  }

  public void setProperty(Property prop, String value) {
    props_.put(prop, value);
  }
  
  public void setBoolProperty(Property prop, boolean bool) {
    props_.put(prop, bool ? "true" : "false");
  }

  private void initProperties() {
    setBoolProperty(Property.SHOW_ANCHORS, true);
    setBoolProperty(Property.SHOW_CORRIDORS, true);
    setBoolProperty(Property.SHOW_LINES, true);
    setBoolProperty(Property.SHOW_GRID, false);
    setBoolProperty(Property.SNAP_TO_GRID, false);
    setBoolProperty(Property.USE_ANTIALIASING, false);

  }



}
